<script src="../include.js"></script>
<script>
    asyncTest((done) => {
        let work = new Worker("worker.js");
        let channel = new MessageChannel();

        function finishTest() {
            println("DONE");
            work.onmessage = null;
            work.terminate();
            channel.port2.onmessage = null;
            done();
        }
        let count = 0;
        work.onmessage = (evt) => {
            println("Got message from worker: " + JSON.stringify(evt.data));
            count++;
            if (count === 3) {
                finishTest();
            }
        };
        channel.port2.onmessage = (evt) => {
            println("Got message from port: " + JSON.stringify(evt.data));
            channel.port2.postMessage("Hello from port2");
            count++;
            if (count === 3) {
                finishTest();
            }
        };
        work.postMessage({ port: channel.port1 }, { transfer : [channel.port1]});
    });
</script>
